﻿@model IEnumerable<IdentityRole>

@{
    ViewBag.Title = "角色列表";
}

<h1>所有的角色列表信息</h1>

@if (Model.Any())
{
    <a class="btn btn-primary mb-3" style="width: auto" asp-action="CreateRole" asp-controller="Admin">添加角色</a>

    foreach (var item in Model)
    {
        <div class="card mb-3">
            <div class="card-header">角色ID：@item.Id</div>
            <div class="card-body">
                <h5 class="card-title">@item.Name</h5>
            </div>
            
            @inject IAuthorizationService AuthorizationService;

            <div class="card-footer">
                <form method="post" asp-action="DeleteRole" asp-route-id="@item.Id">

                    @if ((await AuthorizationService.AuthorizeAsync(User, "EditRolePolicy")).Succeeded)
                    {
                        <a asp-controller="Admin" asp-action="EditRole" asp-route-id="@item.Id" class="btn btn-primary">编辑</a>
                    }

                    <span id="confirmDeleteSpan_@item.Id" style="display: none">
                        <span>你确定你要删除？</span>
                        <button type="submit" class="btn btn-danger">是</button>
                        <a href="#" class="btn btn-primary" onclick="confirmDelete('@item.Id', false)">否</a>
                    </span>
                    <span id="deleteSpan_@item.Id">
                        <a href="#" class="btn btn-danger" onclick="confirmDelete('@item.Id', true)">删除</a>
                    </span>
                </form>
            </div>
        </div>
    }
}
else
{
    <div class="card">
        <div class="card-header">
            尚未创建任何角色信息
        </div>
        <div class="card-body">
            <h5 class="card-title">点击下面的按钮创建角色</h5>
        </div>
        <div class="card-footer">
            <a asp-controller="Admin" asp-action="CreateRole" class="btn btn-primary" style="width: auto">创建角色</a>
        </div>
    </div>
}

@section Scripts
{
    <script src="~/js/CustomScripts.js" asp-append-version="true"></script>
}
